package com.wsjj.yjh;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class ShuffleExample {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);

        DataStreamSource<String> source = env.socketTextStream("hadoop102", 7777);
        KeyedStream<String, String> stringStringKeyedStream =
                source.keyBy(value -> value);

        DataStream<String> shuffle = source.shuffle();
        stringStringKeyedStream.print("key");
        shuffle.print("shuffle");

        env.execute();
    }
}
